package ModelImplementation

import (
	"SoftwareEngineering/Model"
	"time"
)

type CommissionedClassification struct {
	itsCommissionRate float64
	itsSalary         float64
	itsReceipts       map[time.Time]SalesReceipt
}

func (c CommissionedClassification) CommissionedClassification(salary float64, commissionalRate float64) CommissionedClassification{
	c.itsSalary = salary
	c.itsCommissionRate = commissionalRate
	return c
}

func (c CommissionedClassification) GetSalary() float64 {
	return c.itsSalary
}

func (c CommissionedClassification) AddSalesReceipt(sr SalesReceipt) {
	c.itsReceipts[sr.GetSaleDate()] = sr
}

func (c CommissionedClassification) GetReceipt(date time.Time) SalesReceipt {
	return c.itsReceipts[date]
}

func (c CommissionedClassification) GetRate() float64 {
	return c.itsCommissionRate
}

func (c CommissionedClassification) CalculatePay(pc Model.Paycheck) float64 {
	commission := 0.0

	for date, sr := range c.itsReceipts {
		dt1 := pc.GetPayPeriodStartDate()
		dt2 := pc.GetPayPeriodEndDate()

		if date.After(dt1) && date.Before(dt2) {
			commission += sr.GetAmount() * c.itsCommissionRate
		}
	}

	return c.itsSalary+commission
}
